package com.lnj.product.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Component
public class KafkaProducterUtil {
    private final KafkaTemplate<String, String> kafkaTemplate;
    @Autowired
    public KafkaProducterUtil(KafkaTemplate<String, String> kafkaTemplate) {
        this.kafkaTemplate = kafkaTemplate;
    }
    // 发送消息
    public void sendMessage(String topic, String message) {
        kafkaTemplate.send(topic, message);
    }
    // 发送消息
    // 发送消息
    // @param topic 主题
    // @param key 键 判断是什么消息
    // @param message 消息
    public void sendMessage(String topic, String key, String message) {
        kafkaTemplate.send(topic, key, message);
    }
}
